<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/font/css/font-awesome.min.css}"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}"/>
    <![endif]-->
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>
    <script th:src="@{/erp/js/dragDivResize.js}" type="text/javascript"></script>
    <title>添加角色</title>
</head>

<body>
<div class="Competence_add_style clearfix">
    <div class="left_Competence_add">
        <div class="title_name">修改角色</div>
        <div class="Competence_add">
            <form action="/role/refer" type="post">
                <div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1">
                    角色名称 </label>
                    <div class="col-sm-9"><input type="hidden" name="roleid" th:value="${byId.id}"><input type="text" id="form-field-1" th:value="${byId.roleName}" name="rolename"
                      placeholder="最多不超过9位" onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')"  onafterpaste="this.value=this.value.replace(//[^\w\u4E00-\u9FA5]/g,'')" maxlength="9" class="col-xs-10 col-sm-5"></div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1">
                    角色描述 </label>
                    <div class="col-sm-9"><textarea name="roledescribe" class="form-control" id="form_textarea" placeholder=""
                                                    onkeyup="checkLength(this);" th:text="${byId.roleDescribe}"></textarea><span
                            class="wordage">剩余字数：<span id="sy" style="color:Red;">200</span>字</span></div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label no-padding-right"
                                               for="form-field-1"> </label>
                    <div class="col-sm-9">

                    </div>
                </div>
                <!--按钮操作-->
                <div class="Button_operation">
                    <button class="btn btn-primary radius" id="submitaddpermission" type="button" sf><i
                            class="fa fa-save "></i> 保存并提交
                    </button>
                    <a href="javascript:;">
                        <button onclick="window.history.go(-1)" class="btn btn-secondary  btn-warning" type="button"><i
                                class="fa fa-reply"></i> 返回上一步
                        </button>
                    </a>
                    <button onclick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                </div>
            </form>
        </div>
    </div>
    <!--权限分配-->
    <div class="Assign_style">
        <div class="title_name">权限分配</div>
        <div class="Select_Competence">
            <dl class="permission-list" th:each="menu:${menues}">
                <dt><label class="middle"><input name="user-Character-0" class="ace" type="checkbox" th:checked="${menu.menuOpt==true?true:false}" th:value="${menu.id}"><span class="lbl" th:text="${menu.menuName}"></span></label></dt>
                <dd>
                    <dl class="cl permission-list2" th:each="menu1,iterStat:${menu.list}">
                        <dt><label class="middle"><input type="checkbox" class="ace" name="user-Character-0-0" th:checked="${menu1.menuOpt==true?true:false}" th:value="${menu1.id}"><span class="lbl" th:text="${menu1.menuName}"></span></label>
                        </dt>
                    </dl>
                </dd>
            </dl>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    $('#submitaddpermission').click(function () {
        if($('#form-field-1').val()==""){
            alert("用户名不能为空");
        }else{
            var data =[];
            data.push($("input[name='roleid']").val());
            data.push($("input[name='rolename']").val());
            data.push($("textarea[name='roledescribe']").val());
            $("input:checkbox:checked").each(function () {
                data.push($(this).val());
            });
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: '/menu/updaterolemenu',
                data: {ids: data}
            })
            window.location.href="/role/roleManage";
        }
    })
    //初始化宽度、高度
    $(".left_Competence_add,.Competence_add_style").height($(window).height()).val();
    ;
    $(".Assign_style").width($(window).width() - 500).height($(window).height()).val();
    $(".Select_Competence").width($(window).width() - 500).height($(window).height() - 40).val();
    //当文档窗口发生改变时 触发
    $(window).resize(function () {

        $(".Assign_style").width($(window).width() - 500).height($(window).height()).val();
        $(".Select_Competence").width($(window).width() - 500).height($(window).height() - 40).val();
        $(".left_Competence_add,.Competence_add_style").height($(window).height()).val();
        ;
    });

    /*字数限制*/
    function checkLength(which) {
        var maxChars = 200; //
        if (which.value.length > maxChars) {
            layer.open({
                icon: 2,
                title: '提示框',
                content: '您出入的字数超多限制!',
            });
            // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
            which.value = which.value.substring(0, maxChars);
            return false;
        } else {
            var curr = maxChars - which.value.length; //250 减去 当前输入的
            document.getElementById("sy").innerHTML = curr.toString();
            return true;
        }
    };
    /*按钮选择*/
    $(function () {
        $(".permission-list dt input:checkbox").click(function () {
            $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function () {
            var l = $(this).parent().parent().find("input:checked").length;
            var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if ($(this).prop("checked")) {
                $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
            } else {
                if (l == 0) {
                    $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
                }
                if (l2 == 0) {
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
                }
            }

        });
    });

</script>
